package com.qingmu.club.minaapi.controller.member;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.qingmu.club.minaapi.plus.entity.Course;
import com.qingmu.club.minaapi.plus.service.CourseService;
import com.qingmu.club.minaapi.utils.KeyValueDefine;
import com.qingmu.club.minaapi.utils.ResponseObject;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 课程主表 前端控制器
 * </p>
 *测试
 * @author duke
 * @since 2019-08-20
 */
@RestController
@CrossOrigin(origins = "*", methods = {RequestMethod.POST, RequestMethod.GET})
@Api(value = "课程相关(会员端小程序)", description = "课程相关(会员端小程序)")
@RequestMapping("/member/course")
public class MemberCourseController {

    @Autowired
    CourseService courseService;


    @RequestMapping(value = "/selectCourse", method = RequestMethod.POST, produces = "application/json; charset=utf-8")
    @ApiOperation(value = "精选课程")
    public ResponseEntity selectCourse(
            @ApiParam(required = true, value = "门店id") @RequestParam(required = true) String shopId
    ) {
        QueryWrapper<Course> qw = new QueryWrapper<>();
        qw.eq(Course.SHOP_ID,shopId);
        qw.eq(Course.TYPE,KeyValueDefine.COURES); //类型：0课程 1商品
        qw.eq(Course.STATUS, KeyValueDefine.ONLINE_STATUS); //上架
        List<Course> courses  = courseService.list(qw);

        return ResponseObject.success(courses);
    }

    @RequestMapping(value = "/selectGoods", method = RequestMethod.POST, produces = "application/json; charset=utf-8")
    @ApiOperation(value = "轮滑商品")
    public ResponseEntity selectGoods(
            @ApiParam(required = true, value = "门店id") @RequestParam(required = true) String shopId
    ) {
        QueryWrapper<Course> qw = new QueryWrapper<>();
        qw.eq(Course.SHOP_ID,shopId);
        qw.eq(Course.TYPE,KeyValueDefine.GOODS); //类型：0课程 1商品
        qw.eq(Course.STATUS, KeyValueDefine.ONLINE_STATUS); //上架
        List<Course> courses  = courseService.list(qw);

        return ResponseObject.success(courses);
    }

    @RequestMapping(value = "/getById", method = RequestMethod.POST, produces = "application/json; charset=utf-8")
    @ApiOperation(value = "查询课程详情")
    public ResponseEntity getById(
            @ApiParam(required = true, value = "课程id") @RequestParam(required = true) String courseId
    ) {

        Course course  = courseService.getById(courseId);

         if(course==null){
             return ResponseObject.error(601,"课程不存在");
         }
         return  ResponseObject.success(course);
    }


}

